// 设备检测
<template>
    <f7-page class="hntsh">
        <f7-navbar>
            <f7-nav-left>
                <f7-link back icon-material="chevron_left" force></f7-link>
            </f7-nav-left>
            <f7-nav-title>设备检测</f7-nav-title>
            <f7-nav-right> </f7-nav-right>
        </f7-navbar>
        <Steps
            :currentStep="activeStep"
            :activeIndex="currentStep"
            :stepsLabel="stepsLabel"
            @change="onChange"
        />
        <div class="content-list list" v-if="currentStep == 0">
            <van-form class="first-form" ref="form" :readonly="!isWrite">
                <div class="choose-total-box">
                    <van-field
                        v-model="models.property.propertyCode"
                        @click-input="
                            isWrite ? (showDevice = true) : (showDevice = false)
                        "
                        class="choose-box"
                        readonly
                        required
                        :rules="[{ required: true, message: '请输入正确内容' }]"
                        label="检测设备"
                        placeholder="请选择"
                    >
                        <div slot="input" class="input-cell">
                            <div>{{ models.property.propertyCode }}</div>
                            <span class="choose-title">选择</span>
                        </div>
                    </van-field>
                    <div class="choose-content">
                        <div class="choose-item">
                            <div class="label">设备类型</div>
                            <div class="value">
                                {{
                                    models.property.equipmentType
                                        | DictItem(controlData.equipmentType) ||
                                    '--'
                                }}
                            </div>
                        </div>
                        <div class="choose-item">
                            <div class="label">规格型号</div>
                            <div class="value">
                                {{ models.property.normsModel || '--' }}
                            </div>
                        </div>
                        <div class="choose-item">
                            <div class="label">用于工程</div>
                            <div class="value">
                                {{ models.property.engineeName || '--' }}
                            </div>
                        </div>
                        <div class="choose-item">
                            <div class="label">工程地址</div>
                            <div class="value">
                                {{ models.property.engineeAddress || '--' }}
                            </div>
                        </div>
                    </div>
                </div>
                <div class="choose-total-box">
                    <van-field
                        v-model="models.eqmCheck.checkOrgName"
                        @click-input="
                            isWrite ? (showUnit = true) : (showUnit = false)
                        "
                        readonly
                        class="choose-box"
                        required
                        :rules="[{ required: true, message: '请输入正确内容' }]"
                        label="检测单位"
                        placeholder="请选择"
                    >
                        <div slot="input" class="input-cell">
                            <div>{{ models.eqmCheck.checkOrgName }}</div>
                            <span class="choose-title">选择</span>
                        </div>
                    </van-field>
                    <div class="choose-content">
                        <div class="choose-item">
                            <div class="label">统一社会信用代码</div>
                            <div class="value">
                                {{ models.inspectionOrg.creditCode || '--' }}
                            </div>
                        </div>
                        <div class="choose-item">
                            <div class="label">单位地址</div>
                            <div class="value">
                                {{ models.inspectionOrg.address || '--' }}
                            </div>
                        </div>
                    </div>
                </div>
                <div class="choose-total-box">
                    <van-field
                        name="radio"
                        required
                        label="检测类型"
                        :rules="[{ required: true, message: '请输入正确内容' }]"
                        style="align-items: flex-start;"
                    >
                        <van-radio-group
                            slot="input"
                            :disabled="!isWrite"
                            v-model="models.eqmCheck.checkReason"
                        >
                            <van-radio
                                v-for="(item, index) in controlData.checkReason"
                                :key="index"
                                :name="item.code"
                                >{{ item.name }}</van-radio
                            >
                        </van-radio-group>
                    </van-field>
                    <van-field
                        readonly
                        required
                        clickable
                        name="datetimePicker"
                        :value="models.eqmCheck.planCheckTime"
                        label="期望进场时间 "
                        :rules="[{ required: true, message: '请输入正确内容' }]"
                        placeholder="请选择"
                        @click="
                            isWrite ? (showPicker = true) : (showPicker = false)
                        "
                    />

                    <van-popup v-model="showPicker" position="bottom">
                        <van-datetime-picker
                            type="date"
                            @confirm="onConfirm"
                            @cancel="showPicker = false"
                            :min-date="minDate"
                            :max-date="maxDate"
                            :value="currentDate"
                        />
                    </van-popup>
                    <van-field
                        v-model="models.model.contact"
                        label="联系人"
                        rows="1"
                        autosize
                        type="textarea"
                        placeholder="请输入"
                    >
                    </van-field>
                    <van-field
                        v-model="models.model.contactTel"
                        label="联系电话"
                        type="number"
                        placeholder="请输入"
                    >
                    </van-field>
                </div>
                <div
                    class="choose-total-box"
                    v-if="models.eqmCheck.delegateMemo"
                >
                    <div class="memo">{{ models.eqmCheck.delegateMemo }}</div>
                </div>
            </van-form>
            <f7-toolbar position="bottom" no-shadow class="fff" v-if="isWrite">
                <f7-button fill class="submit-btn" @click="sure(1)"
                    >提交</f7-button
                >
            </f7-toolbar>
            <!-- 选择设备 -->
            <v-popup-device
                v-model="showDevice"
                :equipmentTypeList="controlData.equipmentType"
                url="/app/equipment/eqmCheck/queryPropertyList"
                @save="suerDevice"
            >
            </v-popup-device>
            <!-- 选择单位 -->
            <v-popup-unit
                v-model="showUnit"
                url="/app/equipment/eqmCheck/queryOrgList"
                @save="suerUnit"
            >
            </v-popup-unit>
        </div>
        <div class="content-list" v-if="currentStep == 1">
            <v-accordion title="检测确认" class="infoList noBorder" disabled>
                <van-form input-align="right" ref="form1" :readonly="!isWrite1">
                    <van-field
                        name="radio"
                        required
                        label="接受委托"
                        :rules="[
                            { validator: isQual, message: '请输入正确内容' },
                        ]"
                    >
                        <van-radio-group
                            slot="input"
                            :disabled="!isWrite1"
                            v-model="models.eqmCheck.isDelegate"
                            direction="horizontal"
                        >
                            <van-radio
                                v-for="(item, index) in DelegateList"
                                :key="index"
                                :name="item.code"
                                >{{ item.name }}</van-radio
                            >
                        </van-radio-group>
                    </van-field>
                    <van-field
                        readonly
                        :required="models.eqmCheck.isDelegate"
                        clickable
                        name="datetimePicker"
                        :value="models.eqmCheck.delegateTime"
                        label="进场时间"
                        :rules="
                            models.eqmCheck.isDelegate
                                ? [
                                      {
                                          required: true,
                                          message: '请输入正确内容',
                                      },
                                  ]
                                : []
                        "
                        placeholder="请选择"
                        @click="
                            isWrite1
                                ? (showPicker1 = true)
                                : (showPicker1 = false)
                        "
                    />

                    <van-popup v-model="showPicker1" position="bottom">
                        <van-datetime-picker
                            type="date"
                            @confirm="onConfirm1"
                            @cancel="showPicker1 = false"
                            :min-date="minDate"
                            :max-date="maxDate"
                            :value="currentDate"
                        />
                    </van-popup>
                    <van-field
                        v-model="models.eqmCheck.delegateUser"
                        :required="models.eqmCheck.isDelegate"
                        label="联系人"
                        :rules="
                            models.eqmCheck.isDelegate
                                ? [
                                      {
                                          required: true,
                                          message: '请输入正确内容',
                                      },
                                  ]
                                : []
                        "
                        rows="1"
                        autosize
                        type="textarea"
                        placeholder="请输入"
                    >
                    </van-field>
                    <van-field
                        v-model="models.eqmCheck.delegateTel"
                        label="联系电话"
                        :required="models.eqmCheck.isDelegate"
                        type="number"
                        :rules="
                            models.eqmCheck.isDelegate
                                ? [
                                      {
                                          validator: mobileRegex,
                                          message: '请输入正确内容',
                                      },
                                  ]
                                : []
                        "
                        placeholder="请输入"
                    >
                    </van-field>
                </van-form>
            </v-accordion>
            <v-accordion title="检测人员" class="infoList noBorder" disabled>
                <v-person-list
                    :list="models.staffList"
                    :isDisabled="!isWrite1"
                    @delete="deletePerson"
                />
                <div class="btn-box" v-if="isWrite1">
                    <f7-button
                        fill
                        class="submit-btn person-btn"
                        @click="showProject = true"
                    >
                        <van-icon name="plus" size="16px" style="margin-right: 5px"/>
                        添加人员
                    </f7-button>
                </div>
            </v-accordion>
            <v-accordion
                title="检测进场告知书"
                class="infoList noBorder"
                disabled
            >
                <div slot="title">
                    <span style="color:#ee0a24;margin-right: 2px;font-size: 14px;">*</span>
                    检测进场告知书
                </div>
                <qm-file-upload
                    v-if="eqmCheckBookBiz"
                    ref="eqmCheckBook"
                    :galleryOptions="{ multiple: true, maximum: 9 }"
                    :disabled="!isWrite1"
                    :params="{
                        type: 'attach',
                        dataKey: models.model.caseId,
                        bizType: eqmCheckBookBiz,
                    }"
                    uploadId="eqmCheckBook"
                    :isDefaultFile="true"
                    :defaultFiles="eqmCheckBookList"
                >
                </qm-file-upload>
            </v-accordion>
            <f7-toolbar position="bottom" no-shadow class="fff" v-if="isWrite1">
                <f7-button fill class="submit-btn" @click="sure(2)"
                    >提交</f7-button
                >
            </f7-toolbar>
            <!-- 选择人员 -->
            <v-popup-person
                v-model="showProject"
                url="/app/ent/entPersonJob/query"
                @save="suerPart"
                :params="{
                    jobTypeIds:'JCY,JYS'
                }"
            >
            </v-popup-person>
        </div>
        <div class="content-list" v-if="currentStep == 2">
            <div class="tip-box">
                <van-icon name="info-o" size="14px" style="vertical-align: middle;"/>
                此模块由监理进行验证，其它用户无需操作；监理请对检测人员进行人脸拍照验证，系统自动识别！
            </div>
            <v-person-check
                :list="models.staffList"
                @check="checkPerson"
                :disabled="!isWrite2"
                title="检测人员"
            />
            <f7-toolbar position="bottom" no-shadow class="fff" v-if="isWrite2">
                <f7-button fill class="submit-btn" @click="sure(3)"
                    >认证完成</f7-button
                >
            </f7-toolbar>
        </div>
        <div class="content-list" v-if="currentStep == 3">
            <div class="point-title" @click="goKey()">
                <span>检测关键节点</span>
                <span class="num" v-if="controlData.reservedMap.vitalsSum"
                    >{{ controlData.reservedMap.vitals || 0 }}/{{
                        controlData.reservedMap.vitalsSum
                    }}
                    <van-icon name="arrow" size="14px" color="#B5BCCA"/>
                </span>
            </div>
            <div class="point-title" @click="goUnqualified()">
                <span>不合格问题</span>
                <span class="num" v-if="controlData.reservedMap.quertionSum"
                    >{{ controlData.reservedMap.status }}&nbsp&nbsp{{
                        controlData.reservedMap.quertionSum
                    }}
                    <van-icon name="arrow" size="14px" color="#B5BCCA"/>
                </span>
                <span class="num" v-if="!controlData.reservedMap.quertionSum">
                    添加
                    <van-icon name="arrow" size="14px" color="#B5BCCA"/>
                </span>
            </div>
            <v-accordion
                title="检测初步意见"
                class="infoList noBorder"
                disabled
            >
                <van-form input-align="right" ref="form3" :readonly="!isWrite3">
                    <van-field
                        name="radio"
                        required
                        label="初步意见"
                        :rules="[
                            { validator: isQual, message: '请输入正确内容' },
                        ]"
                    >
                        <van-radio-group
                            slot="input"
                            :disabled="!isWrite3"
                            v-model="models.eqmCheck.isPreQualified"
                            direction="horizontal"
                        >
                            <van-radio
                                v-for="(item, index) in conclusionList"
                                :key="index"
                                :name="item.code"
                                >{{ item.name }}</van-radio
                            >
                        </van-radio-group>
                    </van-field>
                    <van-field
                        readonly
                        required
                        clickable
                        name="datetimePicker"
                        :value="models.eqmCheck.checkTime"
                        label="检测时间"
                        :rules="[{ required: true, message: '请输入正确内容' }]"
                        placeholder="请选择"
                        @click="
                            isWrite3
                                ? (showPicker2 = true)
                                : (showPicker2 = false)
                        "
                    />

                    <van-popup v-model="showPicker2" position="bottom">
                        <van-datetime-picker
                            type="date"
                            @confirm="onConfirm2"
                            @cancel="showPicker2 = false"
                            :min-date="minDate"
                            :max-date="maxDate"
                            :value="currentDate"
                        />
                    </van-popup>
                    <van-field
                        v-model="models.eqmCheck.checkUser"
                        required
                        readonly
                        label="检测人员"
                        :rules="[{ required: true, message: '请输入正确内容' }]"
                        rows="1"
                        autosize
                        type="textarea"
                        placeholder="请输入"
                    >
                    </van-field>
                    <van-field
                        v-model="models.eqmCheck.checkDesc"
                        label="其他说明"
                        rows="1"
                        autosize
                        type="textarea"
                        placeholder="请输入"
                    >
                    </van-field>
                    <van-field
                        required
                        readonly
                        label="意见书"
                        class="label-all file"
                    >
                    </van-field>
                    <div v-if="eqmCheckPositionPaperBiz">
                        <qm-file-upload
                            ref="eqmCheckPositionPaper"
                            :galleryOptions="{ multiple: true, maximum: 9 }"
                            :disabled="!isWrite3"
                            :params="{
                                type: 'attach',
                                dataKey: models.model.caseId,
                                bizType: eqmCheckPositionPaperBiz,
                            }"
                            uploadId="eqmCheckPositionPaper"
                            :isDefaultFile="true"
                            :defaultFiles="eqmCheckPositionPaperFileList"
                        >
                        </qm-file-upload>
                    </div>
                </van-form>
            </v-accordion>
            <v-accordion
                title="检测初步意见签名确认"
                class="infoList noBorder"
                disabled
            >
                <div class="sign-tip">
                    委托单位、施工单位、监理单位代表其中一个签名即可
                </div>
                <f7-list class="sign-list">
                    <template>
                        <f7-list-item>
                            <div class="sign-card">
                                <div
                                    class="sign-item"
                                    @click="openSignPopup('recorder1')"
                                >
                                    <img
                                        v-show="signature1"
                                        :src="signature1"
                                        class="view-image sign-image"
                                        width="140"
                                        height="40"
                                    />
                                    <div
                                        v-show="!signature1"
                                        class="sign-title"
                                    >
                                        点我签名
                                    </div>
                                </div>
                                <div class="sign-placehoder">委托单位代表</div>
                            </div>
                        </f7-list-item>
                        <f7-list-item>
                            <div class="sign-card">
                                <div
                                    class="sign-item"
                                    @click="openSignPopup('recorder2')"
                                >
                                    <img
                                        v-show="signature2"
                                        :src="signature2"
                                        class="view-image sign-image"
                                        width="140"
                                        height="40"
                                    />
                                    <div
                                        v-show="!signature2"
                                        class="sign-title"
                                    >
                                        点我签名
                                    </div>
                                </div>
                                <div class="sign-placehoder">施工单位代表</div>
                            </div>
                        </f7-list-item>
                    </template>
                </f7-list>
                <f7-list class="sign-list">
                    <template>
                        <f7-list-item>
                            <div class="sign-card">
                                <div
                                    class="sign-item"
                                    @click="openSignPopup('recorder3')"
                                >
                                    <img
                                        v-show="signature3"
                                        :src="signature3"
                                        class="view-image sign-image"
                                        width="140"
                                        height="40"
                                    />
                                    <div
                                        v-show="!signature3"
                                        class="sign-title"
                                    >
                                        点我签名
                                    </div>
                                </div>
                                <div class="sign-placehoder">监理单位代表</div>
                            </div>
                        </f7-list-item>
                        <f7-list-item>
                            <div class="sign-card">
                                <div
                                    class="sign-item"
                                    @click="openSignPopup('recorder4')"
                                >
                                    <img
                                        v-show="signature4"
                                        :src="signature4"
                                        class="view-image sign-image"
                                        width="140"
                                        height="40"
                                    />
                                    <div
                                        v-show="!signature4"
                                        class="sign-title"
                                    >
                                        点我签名
                                    </div>
                                </div>
                                <div class="sign-placehoder">检测单位代表</div>
                            </div>
                        </f7-list-item>
                    </template>
                </f7-list>
                <qm-sign
                    ref="signSheet"
                    :resignClick="reSignClick"
                    :saveSignCallback="saveSignFunc"
                />
            </v-accordion>
            <f7-toolbar position="bottom" no-shadow class="fff" v-if="isWrite3">
                <f7-button fill class="submit-btn" @click="sure(4)">提交</f7-button>
            </f7-toolbar>
        </div>
        <div class="content-list" v-if="currentStep > 3">
            <v-accordion title="检测报告" class="infoList noBorder" disabled>
                <van-form input-align="right" ref="form4" :readonly="!isWrite4">
                    <van-field
                        v-model="models.eqmCheck.checkHeight"
                        label="检测高度"
                        required
                        type="number"
                        :rules="[{ validator, message: '请输入正确内容' }]"
                        placeholder="请输入"
                    >
                        <span slot="extra">米</span>
                    </van-field>
                    <van-field
                        v-if="models.property.equipmentType=='TSQZJ'"
                        v-model="models.eqmCheck.checkRange"
                        label="检测最大幅度"
                        required
                        type="number"
                        :rules="[{ validator, message: '请输入正确内容' }]"
                        placeholder="请输入"
                    >
                        <span slot="extra">米</span>
                    </van-field>
                    <template v-if="models.property.equipmentType=='SGSJJ'">
                        <van-field
                            v-model="models.eqmCheck.fallArrestor1"
                            required
                            label="防坠器1编号"
                            :rules="[{ required: true, message: '请输入正确内容' }]"
                            rows="1"
                            autosize
                            type="textarea"
                            placeholder="请输入"
                        >
                        </van-field>
                        <van-field
                            readonly
                            required
                            clickable
                            name="datetimePicker"
                            :value="models.eqmCheck.fallArrestorDate1"
                            label="防坠器1过期日期"
                            :rules="[{ required: true, message: '请输入正确内容' }]"
                            placeholder="请选择"
                            @click="
                                isWrite4
                                    ? (showPicker4 = true)
                                    : (showPicker4 = false)
                            "
                        />
                        <van-popup v-model="showPicker4" position="bottom">
                            <van-datetime-picker
                                type="date"
                                @confirm="onConfirm4"
                                @cancel="showPicker4 = false"
                                :min-date="minDate"
                                :max-date="maxDate"
                                :value="currentDate"
                            />
                        </van-popup>
                        <van-field
                            v-model="models.eqmCheck.fallArrestor2"
                            required
                            label="防坠器2编号"
                            :rules="[{ required: true, message: '请输入正确内容' }]"
                            rows="1"
                            autosize
                            type="textarea"
                            placeholder="请输入"
                        >
                        </van-field>
                        <van-field
                            readonly
                            required
                            clickable
                            name="datetimePicker"
                            :value="models.eqmCheck.fallArrestorDate2"
                            label="防坠器2过期日期"
                            :rules="[{ required: true, message: '请输入正确内容' }]"
                            placeholder="请选择"
                            @click="
                                isWrite4
                                    ? (showPicker5 = true)
                                    : (showPicker5 = false)
                            "
                        />
                        <van-popup v-model="showPicker5" position="bottom">
                            <van-datetime-picker
                                type="date"
                                @confirm="onConfirm5"
                                @cancel="showPicker5 = false"
                                :min-date="minDate"
                                :max-date="maxDate"
                                :value="currentDate"
                            />
                        </van-popup>
                    </template>
                    <van-field
                        name="radio"
                        required
                        label="检测结果"
                        :rules="[
                            { validator: isQual, message: '请输入正确内容' },
                        ]"
                    >
                        <van-radio-group
                            slot="input"
                            :disabled="!isWrite4"
                            v-model="models.eqmCheck.isQualified"
                            direction="horizontal"
                        >
                            <van-radio
                                v-for="(item, index) in conclusionList"
                                :key="index"
                                :name="item.code"
                                >{{ item.name }}</van-radio
                            >
                        </van-radio-group>
                    </van-field>
                    <van-field
                        v-model="models.eqmCheck.checkCode"
                        required
                        label="报告编号"
                        :rules="[{ required: true, message: '请输入正确内容' }]"
                        rows="1"
                        autosize
                        type="textarea"
                        placeholder="请输入"
                    >
                    </van-field>
                    <van-field
                        readonly
                        required
                        clickable
                        name="datetimePicker"
                        :value="models.eqmCheck.resultTime"
                        label="报告生成日期"
                        :rules="[{ required: true, message: '请输入正确内容' }]"
                        placeholder="请选择"
                        @click="
                            isWrite4
                                ? (showPicker3 = true)
                                : (showPicker3 = false)
                        "
                    />
                    <van-popup v-model="showPicker3" position="bottom">
                        <van-datetime-picker
                            type="date"
                            @confirm="onConfirm3"
                            @cancel="showPicker3 = false"
                            :min-date="minDate"
                            :max-date="maxDate"
                            :value="currentDate"
                        />
                    </van-popup>
                    <van-field
                        class="textarea-field"
                        v-model="models.eqmCheck.checkMemo"
                        label="检测内容"
                        required
                        :rules="[{ required: true, message: '请输入正确内容' }]"
                        rows="3"
                        autosize
                        type="textarea"
                        placeholder="请输入"
                    >
                    </van-field>
                    <van-field
                        readonly
                        label="检测报告"
                        required
                        class="label-all file"
                    >
                    </van-field>
                    <qm-file-upload
                        v-if="eqmCheckReportBiz"
                        ref="eqmCheckReport"
                        :galleryOptions="{ multiple: true, maximum: 9 }"
                        :disabled="!isWrite4"
                        :params="{
                            type: 'attach',
                            dataKey: models.model.caseId,
                            bizType: eqmCheckReportBiz,
                        }"
                        uploadId="eqmCheckReport"
                        :isDefaultFile="true"
                        :defaultFiles="eqmCheckReportList"
                    >
                    </qm-file-upload>
                </van-form>
            </v-accordion>
            <f7-toolbar position="bottom" no-shadow class="fff" v-if="isWrite4">
                <f7-button fill class="submit-btn plain-btn" @click="sure(6)">保存草稿</f7-button>
                <f7-button fill class="submit-btn" @click="sure(5)"
                    >提交</f7-button
                >
            </f7-toolbar>
        </div>
        <!-- 审核意见 -->
        <v-popup-opinion
            v-model="showPinion"
            :selectUser="selectUser"
            :label="label"
            ref="opinion"
            @save="emitSave"
        >
        </v-popup-opinion>
        <!-- 审核意见 end -->
    </f7-page>
</template>

<script>
import Config from '@/libs/config.js'
import Steps from '../maintenance/components/steps.vue'
import vPopupPerson from '../maintenance/components/v-popup-person.vue'
import vPopupDevice from './components/v-popup-device.vue'
import vPopupUnit from './components/v-popup-unit.vue'
import controller from '@/libs/framework/workflowController'
export default class instance extends controller {
    onBeforeInit() {
        this.urls = {
            model: '/app/equipment/eqmCheck/workflow/getWorkflowViewModel',
            save: '/app/equipment/eqmCheck/workflow/processRun',
        }
    }
    onInit() {}
    onAfterQuery(type, isSuccess, result) {
        if (type == 'form') {
            let activeStep=localStorage.getItem('deviceActiveStep')||''
            activeStep=Number(activeStep)
            if (result.models.eqmCheck.checkStatus != null&&activeStep=='') {
                this.$data.activeStep =  result.models.eqmCheck.checkStatus + 1
                this.$data.currentStep = result.models.eqmCheck.checkStatus + 1
            } else {
                this.$data.currentStep = activeStep||0
                this.$data.activeStep = activeStep||0
            }
            if (!result.controlData.reservedMap) {
                result.controlData.reservedMap = {}
            }
            this.vm.formaTime(result.models.eqmCheck, 'planCheckTime')
            this.vm.formaTime(result.models.eqmCheck, 'delegateTime')
            this.vm.formaTime(result.models.eqmCheck, 'checkTime')
            this.vm.formaTime(result.models.eqmCheck, 'resultTime')
            if (result.models.signBusinessList.length == 0) {
                result.models.signBusinessList = [
                    {
                        mainTablePkId: Math.uuid(),
                        userDataKey: result.controlData.currentUser.userId,
                        sort: 1,
                        signImg: '',
                        dataType: 'signProxy',
                    },
                    {
                        mainTablePkId: Math.uuid(),
                        userDataKey: result.controlData.currentUser.userId,
                        sort: 2,
                        signImg: '',
                        dataType: 'signConstruction',
                    },
                    {
                        mainTablePkId: Math.uuid(),
                        userDataKey: result.controlData.currentUser.userId,
                        sort: 3,
                        signImg: '',
                        dataType: 'signSupervisor',
                    },
                    {
                        mainTablePkId: Math.uuid(),
                        userDataKey: result.controlData.currentUser.userId,
                        sort: 4,
                        signImg: '',
                        dataType: 'signDetection',
                    },
                ]
            } else {
                this.$data.signature1 =
                    result.models.signBusinessList[0].signImg
                this.$data.signature2 =
                    result.models.signBusinessList[1].signImg
                this.$data.signature3 =
                    result.models.signBusinessList[2].signImg
                this.$data.signature4 =
                    result.models.signBusinessList[3].signImg
            }

            // 检测进场告知书
            this.vm.getFile(
                'EQM_CHECK_ENTRANCE',
                result.models.model.caseId,
                result.models.property.equipmentType,
                'eqmCheckBookBiz',
                'eqmCheckBookList'
            )

            // 初步意见书
            this.vm.getFile(
                'EQM_CHECK_SUBMISSION',
                result.models.model.caseId,
                result.models.property.equipmentType,
                'eqmCheckPositionPaperBiz',
                'eqmCheckPositionPaperFileList'
            )

            // 检测报告
            this.vm.getFile(
                'EQM_CHECK_REPORT',
                result.models.model.caseId,
                result.models.property.equipmentType,
                'eqmCheckReportBiz',
                'eqmCheckReportList'
            )
        }
        return result
    }

    onAfterSave(isSuccess, result) {
        // if (isSuccess) {
        //     this.$f7.views.current.router.back()
        // }
    }

    mixin() {
        return {
            components: {
                Steps,
                vPopupPerson,
                vPopupDevice,
                vPopupUnit,
            },
            data() {
                return {
                    eqmCheckPositionPaperFileList:[],
                    eqmCheckReportList:[],
                    eqmCheckBookList:[],
                    minDate: new Date(2017, 0, 1),
                    maxDate: new Date(2080, 12, 1),
                    currentDate: new Date(),
                    showPicker: false,
                    showPicker1: false,
                    showPicker2: false,
                    showPicker3: false,
                    showPicker4: false,
                    showPicker5: false,
                    download: Config.api.download,
                    controlData: {
                        auditInfo: {},
                        workflow: {
                            history: [],
                        },
                        reservedMap: {},
                    },
                    models: {
                        eqmCheck: {
                            isDelegate: '',
                        },
                        model: {},
                        inspectionOrg: {},
                        property: {},
                        signBusinessList: [],
                        staffList: [],
                    },
                    pageAction: '',
                    selectUser: {
                        selectComment: null,
                        comment: null,
                        comments: [],
                        tran: [],
                        activity: '',
                        users: [],
                    },
                    stepsLabel: [
                        {
                            name: '委托检测',
                            img: 'jc-wtjc',
                        },
                        {
                            name: '检测确认',
                            img: 'jc-jcqr',
                        },
                        {
                            name: '人员核对',
                            img: 'jc-ryhd',
                        },
                        {
                            name: '检测现场',
                            img: 'jc-jcxc',
                        },
                        {
                            name: '检测报告',
                            img: 'jc-jcbg',
                        },
                    ],
                    currentStep: null,
                    activeStep: null,
                    personList: [],
                    showProject: false,
                    showDevice: false,
                    showUnit: false,
                    signature1: null,
                    signature2: null,
                    signature3: null,
                    signature4: null,
                    conclusionList: [
                        {
                            name: '合格',
                            code: true,
                        },
                        {
                            name: '不合格',
                            code: false,
                        },
                    ],
                    DelegateList: [
                        {
                            name: '接受委托',
                            code: true,
                        },
                        {
                            name: '不接受委托',
                            code: false,
                        },
                    ],
                    showPinion: false,
                    opinionNum: '',
                    label: '',
                    eqmCheckBookBiz: '',
                    eqmCheckPositionPaperBiz: '',
                    eqmCheckReportBiz: '',
                    address: '',
                }
            },
            computed: {
                isWrite() {
                    var isWrite = false
                    if (
                        this.models.eqmCheck.checkStatus == null &&
                        this.pageAction != 'view'
                    ) {
                        isWrite = true
                    }
                    return isWrite
                },
                isWrite1() {
                    var isWrite = false
                    if (
                        this.models.eqmCheck.checkStatus === 0 &&
                        this.pageAction != 'view'
                    ) {
                        isWrite = true
                    }
                    return isWrite
                },
                isWrite2() {
                    var isWrite = false
                    if (
                        this.models.eqmCheck.checkStatus === 1 &&
                        this.pageAction != 'view'
                    ) {
                        isWrite = true
                    }
                    return isWrite
                },
                isWrite3() {
                    var isWrite = false
                    if (
                        this.models.eqmCheck.checkStatus === 2 &&
                        this.pageAction != 'view'
                    ) {
                        isWrite = true
                    }
                    return isWrite
                },
                isWrite4() {
                    var isWrite = false
                    if (
                        this.models.eqmCheck.checkStatus === 3 &&
                        this.pageAction != 'view'
                    ) {
                        isWrite = true
                    }
                    return isWrite
                },
            },
            mounted() {
                this.loadLocation()
            },
            methods: {
                //获取地址
                loadLocation() {
                    let self = this
                    self.$util.getCurrentPosition(
                        (pos) => {
                            if (pos.addresses) {
                                self.address = pos.addresses
                            } else if (pos.data) {
                                self.address = pos.data.name
                            }
                        },
                        (error) => {
                            // self.$f7.dialog.toast(
                            //     '获取定位失败,请确认是否授权定位功能'
                            // )
                        }
                    )
                },
                getFile(typeCode, dataKey, attachCraneType, biz,list) {
                    this.$f7.request.post(
                        '/admin/attachmentFormDetail/listUpload',
                        {
                            typeCode: typeCode,
                            dataKey: dataKey,
                            attachCraneType: attachCraneType,
                        },
                        (r) => {
                            r = JSON.parse(r)
                            if (r?.success && r.parameters.fileList) {
                                this[list]=r.parameters.fileList[0].attachments
                                this[`${biz}`] =
                                    r.parameters.fileList[0].bizType
                            } else {
                                this.$framework.$f7.dialog.toast('获取文件失败')
                            }
                        }
                    )
                },
                //格式化时间
                formaTime(arr, name) {
                    if (arr[name]) {
                        arr[name] = formatter.formatDate(
                            arr[name],
                            'yyyy-MM-dd'
                        )
                    }
                    // if (name == 'checkTime' && !arr[name]) {
                    //     arr[name] = formatter.formatDate(
                    //         new Date(),
                    //         'yyyy-MM-dd'
                    //     )
                    // }
                },
                onChange(index) {
                    // 父组件获取切换后的选中步骤
                    this.currentStep = index
                    localStorage.setItem('deviceActiveStep',index)
                },
                saveDraft(){
                    if (!this.models.eqmCheck.checkFileList) {
                        delete this.models.eqmCheck.checkFileList
                    }
                    this.models.signBusinessList[0].signImg = this.signature1
                    this.models.signBusinessList[1].signImg = this.signature2
                    this.models.signBusinessList[2].signImg = this.signature3
                    this.models.signBusinessList[3].signImg = this.signature4
                    this.super.save(this.models,false,'',false)
                },
                //检测关键节点
                goKey() {
                    if(this.isWrite3) {
                        if (!this.models.eqmCheck.checkFileList) {
                            delete this.models.eqmCheck.checkFileList
                        }
                        this.saveDraft()
                    }
                    this.$f7router.navigate(
                        `/business/qzjx/deviceMonitor/keyNode`,
                        {
                            props: {
                                caseId: this.models.model.caseId,
                                isWrite: this.isWrite3,
                                address: this.address,
                            },
                        }
                    )
                },
                //不合格问题
                goUnqualified() {
                    if (this.isWrite3) {
                        this.saveDraft()
                        this.$f7router.navigate(
                            `/business/qzjx/deviceMonitor/unqualified`,
                            {
                                props: {
                                    checkId: this.models.eqmCheck.checkId,
                                    caseId: this.models.model.caseId,
                                    propertyId: this.models.model.propertyId,
                                },
                            }
                        )
                    } else if (this.models.eqmCheck.checkStatus > 2) {
                        this.$f7router.navigate(
                            `/business/qzjx/deviceMonitor/checkUnqualified`,
                            {
                                props: {
                                    checkId: this.models.eqmCheck.checkId,
                                    caseId: this.models.model.caseId,
                                    propertyId: this.models.model.propertyId,
                                    orgTypeCode:
                                        this.controlData.prjEngineeOrg
                                            .orgTypeCode,
                                    isCheckOrg: this.controlData.isCheckOrg,
                                    status: this.controlData.reservedMap.status,
                                },
                            }
                        )
                    }
                },
                //确定期望进场时间
                onConfirm(time) {
                    this.models.eqmCheck.planCheckTime =
                        this.$formatter.formatDate(time, 'yyyy-MM-dd')
                    this.showPicker = false
                },
                //确定进场时间
                onConfirm1(time) {
                    this.models.eqmCheck.delegateTime =
                        this.$formatter.formatDate(time, 'yyyy-MM-dd')
                    this.showPicker1 = false
                },
                //确定检测时间
                onConfirm2(time) {
                    this.models.eqmCheck.checkTime = this.$formatter.formatDate(
                        time,
                        'yyyy-MM-dd'
                    )
                    this.showPicker2 = false
                },
                //报告生成日期
                onConfirm3(time) {
                    this.models.eqmCheck.resultTime =
                        this.$formatter.formatDate(time, 'yyyy-MM-dd')
                    this.showPicker3 = false
                },
                //防坠器1标定日期
                onConfirm4(time) {
                    this.models.eqmCheck.fallArrestorDate1 =
                        this.$formatter.formatDate(time, 'yyyy-MM-dd')
                    this.showPicker4 = false
                },
                //防坠器2标定日期
                onConfirm5(time) {
                    this.models.eqmCheck.fallArrestorDate2 =
                        this.$formatter.formatDate(time, 'yyyy-MM-dd')
                    this.showPicker5 = false
                },
                deletePerson(index) {
                    if (this.isWrite1) {
                        this.models.staffList.splice(index, 1)
                    }
                },
                checkPerson(index) {
                    this.models.staffList[index].authTime =
                        this.$formatter.formatDate(
                            new Date(),
                            'yyyy-MM-dd hh:mm:ss'
                        )
                },
                //选择人员
                suerPart(personList) {
                    this.models.staffList=JSON.parse(JSON.stringify(personList))
                    // if (result.length > 0) {
                    //     this.models.staffList = []
                    //     personList.forEach((element) => {
                    //         result.forEach((element2) => {
                    //             if (element2 == element.certId) {
                    //                 this.models.staffList.push(element)
                    //             }
                    //         })
                    //     })
                    // }
                },
                //选择设备
                suerDevice(result) {
                    if (result.propertyId) {
                        this.models.model.propertyId = result.propertyId
                        this.models.model.propertyCode = result.propertyCode

                        this.models.property.propertyId = result.propertyId
                        this.models.property.propertyCode = result.propertyCode
                        this.models.property.groupId = result.groupId
                        this.models.property.engineeId = result.engineeId
                        this.models.property.equipmentType =
                            result.equipmentType
                        this.models.property.normsModel = result.normsModel
                        this.models.property.engineeName = result.engineeName
                        this.models.property.engineeAddress =
                            result.engineeAddress
                    }
                },
                //选择单位
                suerUnit(result) {
                    if (result.enterpriseId) {
                        this.models.eqmCheck.checkOrgId = result.enterpriseId
                        this.models.eqmCheck.checkOrgName =
                            result.enterpriseName
                        this.models.inspectionOrg.creditCode = result.creditCode
                        this.models.inspectionOrg.address = result.address
                    }
                },
                //手机号校验
                mobileRegex(val) {
                    if (!val) {
                        return false
                    } else {
                        return /^0{0,1}(13[0-9]|14[01456789]|15[012356789]|16[2567]|17[012345678]|18[0-9]|19[012356789])[0-9]{8}$/.test(
                            val
                        )
                    }
                },
                //数字校验
                validator(val) {
                    if (val) {
                        return /(^[1-9]\d*$)|(^[0-9]+.?[0-9]*$)/.test(val)
                    } else {
                        return false
                    }
                },
                //单选框校验
                isQual(val) {
                    if (val == null) {
                        return false
                    }
                },
                //签名
                openSignPopup: function (crnSignType) {
                    var self = this
                    if (!self.isWrite3) {
                        return
                    }
                    self.signType = crnSignType
                    self.$refs.signSheet.openAction()
                    self.isShowReSignBtn()
                    self.isShowNextSignBtn()
                },
                isShowReSignBtn: function () {
                    var self = this
                    self.$refs.signSheet.isShowReSignBtn(true)
                },
                isShowNextSignBtn: function () {
                    var self = this
                    self.$refs.signSheet.isShowNextBtn(false)
                },
                reSignClick: function () {
                    var self = this
                    if (self.signType == 'recorder1') {
                        self.signature1 = null
                    } else if (self.signType == 'recorder2') {
                        self.signature2 = null
                    } else if (self.signType == 'recorder3') {
                        self.signature3 = null
                    } else {
                        self.signature4 = null
                    }
                },
                saveSignFunc: function (signImg, isNext) {
                    if (!signImg) {
                        return
                    }
                    var self = this
                    if (self.signType == 'recorder1') {
                        self.signature1 = signImg
                    } else if (self.signType == 'recorder2') {
                        self.signature2 = signImg
                    } else if (self.signType == 'recorder3') {
                        self.signature3 = signImg
                    } else {
                        self.signature4 = signImg
                    }
                },
                //提交
                sure(index) {
                    var self = this
                    self.models.caseId = self.models.model.caseId
                    if (!self.models.eqmCheck.checkFileList) {
                        delete self.models.eqmCheck.checkFileList
                    }
                    if (index == 1) {
                        self.$refs.form
                            .validate()
                            .then((_) => {
                                self.send()
                            })
                            .catch((err) => {
                                console.log(err)
                            })
                    } else if (index == 2) {
                        if (self.models.eqmCheck.isDelegate == null) {
                            self.$toast('请填写表单内容')
                            return false
                        }
                        if (self.models.eqmCheck.isDelegate) {
                            self.$refs.form1
                                .validate()
                                .then((_) => {
                                    if (self.models.staffList.length == 0) {
                                        self.$toast('请至少添加一位检测人员')
                                        return
                                    }
                                    if (
                                        self.$refs.eqmCheckBook.getUploadedCount() <
                                        1
                                    ) {
                                        self.$toast('请上传检测进场告知书')
                                        return
                                    }
                                    self.send()
                                })
                                .catch((err) => {
                                    console.log(err)
                                })
                        } else {
                            this.opinionNum = 1
                            this.showPinion = true
                            this.label = '不接受原因'
                        }
                    } else if (index == 3) {
                        let flag = this.models.staffList.every(function (
                            currentValue
                        ) {
                            return currentValue.authTime
                        })
                        if (!flag) {
                            self.$toast('人员未全部核对！')
                            return
                        }
                        self.send()
                    } else if (index == 4) {
                        self.$refs.form3
                            .validate()
                            .then((_) => {
                                if (
                                    self.$refs.eqmCheckPositionPaper.getUploadedCount() <
                                    1
                                ) {
                                    self.$toast('请上传意见书')
                                    return false
                                }
                                let arr = [
                                    self.signature1,
                                    self.signature2,
                                    self.signature3,
                                ]
                                let flag = arr.some(function (currentValue) {
                                    return currentValue != null
                                })
                                if (!flag || self.signature4 == null) {
                                    self.$toast('签名确认未完成！')
                                    return
                                }
                                self.models.signBusinessList[0].signImg =
                                    self.signature1
                                self.models.signBusinessList[1].signImg =
                                    self.signature2
                                self.models.signBusinessList[2].signImg =
                                    self.signature3
                                self.models.signBusinessList[3].signImg =
                                    self.signature4
                                self.send()
                            })
                            .catch((err) => {
                                console.log(err)
                            })
                    } else if (index == 5) {
                        self.$refs.form4
                            .validate()
                            .then((_) => {
                                if (
                                    self.$refs.eqmCheckReport.getUploadedCount() <
                                    1
                                ) {
                                    self.$toast('请上传检测报告')
                                    return false
                                }
                                self.send()
                            })
                            .catch((err) => {
                                console.log(err)
                            })
                    } else if(index == 6) {
                        // 检测报告-保存草稿
                        self.save()
                    }
                },
                // 提交
                emitSave() {
                    if (!this.selectUser.comment) {
                        this.$toast('请填写内容')
                        return false
                    }
                    if (this.opinionNum == 1) {
                        this.models.eqmCheck.delegateMemo =
                            this.selectUser.comment
                        this.showPinion = false
                        this.send()
                    }
                },
            },
        }
    }
}
</script>

<style lang="less" scoped>
@import url('../../../../assets/css/qualityCreate.less');
@deep: ~'>>>';

@{deep} .page-content {
    overflow-x: hidden;
    padding-top: 0;
}

.hntsh {
    .content-list {
        padding: 0 0 50px;
        margin: 0;
        .choose-total-box {
            margin:10px 16px;
            padding-top:16px;
            background: #FFFFFF;
            box-shadow: 0px 3px 8px 0px rgba(165,201,255,0.1);
            border-radius: 8px;
            .memo{
                font-size: 13px;
                color: #333;
                padding: 0 16px 16px;
            }
            @{deep}.van-cell{
               background:transparent;
            }
            &:first-child{
                margin-top:18px;
            }
            .choose-content{
                padding: 4px 20px 16px;
                font-size: 13px;
                color: #8995AC;
                .choose-item{
                    display:flex;
                    margin-top: 6px;
                    .label{
                        min-width: 52px;
                        flex-shrink: 0;
                    }

                }
                .value{
                    color: #61677A;
                    margin-left:18px;
                }
            }
            @{deep} .van-radio {
                margin-top: 5px;
            }

            @{deep} .van-radio-group {
                margin-bottom: 5px;
            }
        }
        .point-title{
            padding:16px;
            background:#fff;
            margin:16px;
            color: #333333;
            font-size:14px;
            border-radius: 8px;
            display: flex;
            align-items: center;
            justify-content: space-between;
            .num{
                color: #1990FF;
            }
            @{deep} .icon{
                color:#B5BCCA;
                padding-bottom:1px;
            }
        }
        .first-form{
            @{deep}.van-field__label{
                width: 28%;
                font-size: 14px;
                font-weight: 500;
                color: #333333;
            }
            .choose-box{
                @{deep}.input-cell{
                    display: flex;
                    align-items: center;
                    justify-content:space-between;
                    font-size: 14px;
                    font-weight: 500;
                    color: #333333;
                }
                @{deep}.van-field__label{
                    width: 20%;
                }
                @{deep}&.van-cell{
                    align-items: flex-start!important;
                }

                .choose-title{
                    font-size: 14px;
                    color: #1990FF;
                    min-width: 34px;
                    text-align: right;
                }
            }
            @{deep}.van-cell.choose-box{
                padding: 0 16px 5px;
            }
        }
    }
    @{deep} .pic_upload {
        padding-top: 10px;
    }

    @{deep} .toolbar,
    @{deep}.navbar {
        position: fixed;
    }
    @{deep} .van-form .van-radio__label{
        text-align:left;
    }
    @{deep} .van-form .van-cell--required::before{
        top: 4px;
    }
    @{deep} .van-form .textarea-field .van-field__label{
        padding-top: 4px;
    }
    @{deep} .van-form .textarea-field{
        align-items: flex-start;
    }
    @{deep} .van-form .van-field__label{
        width: 35%;
    }
    .sign-tip{
        font-size:12px;
        color: #737D8A;
        margin-left:16px;
    }
    .wbList {
        .content-box {
            padding: 10px 15px;
            display: flex;
            align-items: flex-start;
        }

        .index-box {
            padding: 2px 8px;
            background: rgba(51, 133, 255, 0.1);
            border-radius: 1px;
            font-size: 13px;
            color: #1990ff;
        }

        .right-box {
            margin-left: 10px;
            font-size: 14px;
            color: #333;
            flex: 1;
        }

        @{deep}.van-cell {
            &::after {
                left: 0;
                right: 0;
            }
            padding: 0;
        }

        @{deep}.van-cell--required::before {
            left: 0;
        }
    }

    @{deep}.m-steps-area
        .m-steps
        .m-steps-item
        .m-info-wrap
        .m-steps-content
        .u-steps-title:after {
        left: 42px;
    }
}
</style>
